package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.supplier3.SupplierEntity3;
import com.swgk.core.dialog.BaseBottomDialog;
import com.swgk.core.dialog.DialogViewHolder;
import com.swgk.core.util.MToast;

public class GoodsPriceDialog3 extends BaseBottomDialog {

    private SupplierEntity3 supplierEntity3;
    private DialogClickCallBack dialogClickCallBack;
    private LinearLayout addLayout;
    private LinearLayout reduceLayout;
    private LinearLayout addPriceLayout;
    private LinearLayout reducePriceLayout;
    private TextView addView;
    private TextView reduceView;
    private TextView addLineView;
    private TextView reduceLineView;
    private TextView cancelView;
    private TextView okView;
    private EditText addText;
    private EditText reduceText;
    private String type = "1";
    private String price = "";
    private float minPrice = 0;

    public GoodsPriceDialog3(Context context, DialogCallBack dialogCallBack) {
        super(context, dialogCallBack);
    }

    public GoodsPriceDialog3(Context context, int theme, DialogCallBack dialogCallBack) {
        super(context, theme, dialogCallBack);
    }

    @Override
    protected int dialogLayout() {
        return R.layout.goods_price_dialog3;
    }

    @Override
    protected void initView(DialogViewHolder holder, Bundle savedInstanceState) {
        addLayout = holder.getDialog().findViewById(R.id.add_layout);
        reduceLayout = holder.getDialog().findViewById(R.id.reduce_layout);
        addView = holder.getDialog().findViewById(R.id.add_view);
        reduceView = holder.getDialog().findViewById(R.id.reduce_view);
        addLineView = holder.getDialog().findViewById(R.id.add_line_view);
        reduceLineView = holder.getDialog().findViewById(R.id.reduce_line_view);
        addPriceLayout = holder.getDialog().findViewById(R.id.add_price_layout);
        reducePriceLayout = holder.getDialog().findViewById(R.id.reduce_price_layout);
        addText = holder.getDialog().findViewById(R.id.add_text);
        reduceText = holder.getDialog().findViewById(R.id.reduce_text);
        cancelView = holder.getDialog().findViewById(R.id.cancel_view);
        okView = holder.getDialog().findViewById(R.id.ok_view);
        addLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                type = "1";
                addView.setTextColor(getContext().getResources().getColor(R.color.color_0286DF));
                addLineView.setVisibility(View.VISIBLE);
                reduceView.setTextColor(getContext().getResources().getColor(R.color.color_969696));
                reduceLineView.setVisibility(View.GONE);
                addPriceLayout.setVisibility(View.VISIBLE);
                reducePriceLayout.setVisibility(View.GONE);
            }
        });
        reduceLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                type = "2";
                addView.setTextColor(getContext().getResources().getColor(R.color.color_969696));
                addLineView.setVisibility(View.GONE);
                reduceView.setTextColor(getContext().getResources().getColor(R.color.color_0286DF));
                reduceLineView.setVisibility(View.VISIBLE);
                addPriceLayout.setVisibility(View.GONE);
                reducePriceLayout.setVisibility(View.VISIBLE);
            }
        });
        cancelView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        okView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (type.equals("1")) {
                    price = addText.getText().toString();
                } else if (type.equals("2")) {
                    price = reduceText.getText().toString();
                }
                if (price.equals("")) {
                    MToast.showToast(getContext(), "请输入金额");
                    return;
                }
                if (type.equals("2")) {
                    if (Float.parseFloat(price) > minPrice) {
                        MToast.showToast(getContext(), "减少的金额不能大于" + minPrice + "元");
                        return;
                    }
                }
                if (dialogClickCallBack != null) {
                    dialogClickCallBack.onClickResult(price, type);
                }
                dismiss();
            }
        });
    }

    public SupplierEntity3 getData() {
        return supplierEntity3;
    }

    public GoodsPriceDialog3 setData(SupplierEntity3 supplierEntity3) {
        this.supplierEntity3 = supplierEntity3;
        return this;
    }

    public GoodsPriceDialog3 setMinPrice(float minPrice) {
        this.minPrice = minPrice;
        return this;
    }

    public interface DialogClickCallBack {
        void onClickResult(String price, String type);
    }

    public GoodsPriceDialog3 setDialogClickCallBack(DialogClickCallBack dialogClickCallBack) {
        this.dialogClickCallBack = dialogClickCallBack;
        return this;
    }
}
